<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>web调取摄像头</title>
</head>
<body>
    <video src=""></video>
    <script src="./vconsole.min.js"></script>
<script>
    var vConsole = new VConsole();
    if (navigator.mediaDevices === undefined) {
        navigator.mediaDevices = {};
    }
    if (navigator.mediaDevices.getUserMedia === undefined) {
        navigator.mediaDevices.getUserMedia = function(constraints) {
            var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
            if (!getUserMedia) {
                return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
            }
            return new Promise(function(resolve, reject) {
                getUserMedia.call(navigator, constraints, resolve, reject);
            });
        }
    }
window.URL = (window.URL || window.webkitURL || window.mozURL || window.msURL);
        var mediaOpts = {
            audio: false,
            video: true,
        }
            function successFunc(stream) {
                var video = document.querySelector('video');
                if ("srcObject" in video) {
                    video.srcObject = stream
                } else {
                    video.src = window.URL && window.URL.createObjectURL(stream) || stream
                }
                video.play();
            }
            function errorFunc(err) {
                alert(err.name);
            }

            navigator.getUserMedia(mediaOpts, successFunc, errorFunc);
    </script>
</body>
</html>
